<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/vue.js"></script>
</head>

<body>
    <div id="app">
        <div>
            <p>{{count}}</p>
            <button>点击</button>
        </div>
        <hr>
        <prop-test id="demo" class="test" title="hello" a="1" b="2" :count="count" :data-id="0"></prop-test>
    </div>
</body>
<script>

    // 父传子 =>  如果要修改父组件传递的数据 => 创建新值 => 变相修改 (不影响父组件的数据)

    Vue.component("prop-test", {
        props: ["a", "b", "count", "data-id"],
        data() {
            return {
                newA: this.a,
                newCount: this.count,
            }
        },
        computed: {
            // newCount() {  // => newCount无法赋值
            //     return this.count;
            // }
            // newCount: {
            //     get() {  // => newCount无法赋值
            //         return this.count;
            //     },
            //     set(val) {
            //         // newCount无法赋值   => 没有地方存
            //     }
            // }
        },
        watch: {
            count: function (newVal) {
                this.newCount = count;
            }
        },
        template: `<div>这是一个测试组件</div>`,
        mounted() {
            console.log(this);
            console.log(this.$props);
            this.a++;
            this.newCount++;
        },
    })


    var vm = new Vue({
        el: "#app",
        data: {
            count: 1,
        }
    })

</script>

</html>